package main

import "sort"

func arrayPairSum(nums []int) int {
	sort.Ints(nums)

	sum := 0

	getMin := func(a, b int) int {
		if a > b {
			return b
		}

		return a
	}

	for i := 0; i < len(nums); i += 2 {
		sum += getMin(nums[i], nums[i+1])
	}

	return sum
}
